//
//  UITableView+EmptyData.m
//  BusinessEnterprise
//
//  Created by LHF on 16/10/20.
//  Copyright © 2016年 YiWang. All rights reserved.
//

#import "UITableView+EmptyData.h"

@implementation UITableView (EmptyData)

- (void)tableViewDisplayWitMsg:(NSString *) message
        ifNecessaryForRowCount:(NSUInteger) rowCount
                        hasImg:(BOOL)hasImg
{
    if (rowCount == 0) {
        // Display a message when the table is empty
        // 没有数据的时候，UILabel的显示样式
        if (hasImg) {
            UIView *bgView = [[UIView alloc] initWithFrame:self.backgroundView.frame];
            UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake((self.frame.size.width - 83) / 2, (self.frame.size.height - 79) / 2 - 40, 83, 79)];
            imgView.image = [UIImage imageNamed:@"no_message"];
            [bgView addSubview:imgView];
            
            UILabel *messageLabel = [UILabel new];
            messageLabel.text = message;
            messageLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
            messageLabel.textColor = [UIColor lightGrayColor];
            messageLabel.textAlignment = NSTextAlignmentCenter;
            [messageLabel sizeToFit];
            [messageLabel setFrame:CGRectMake(0, imgView.frame.origin.y + imgView.frame.size.height + 10 , bgView.frame.size.width, 40)];
            [bgView addSubview:messageLabel];
            
            self.backgroundView = bgView;
        }else
        {
            UILabel *messageLabel = [UILabel new];
            
            messageLabel.text = message;
            messageLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
            messageLabel.textColor = [UIColor lightGrayColor];
            messageLabel.textAlignment = NSTextAlignmentCenter;
            [messageLabel sizeToFit];
            
            self.backgroundView = messageLabel;
            self.separatorStyle = UITableViewCellSeparatorStyleNone;
        }
    } else {
        self.backgroundView = nil;
//        self.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    }
}

@end
